﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Automotriz.Core;
using System.Data;
using System.Data.SqlClient;
using Crosland.Automotriz.Entidad;
using System.Data.Objects;

namespace Crosland.Automotriz.Data.Dao.Linq
{
    public class clsGetJobStatus
    {

        public string JobStatus(string nameJob)
        {
            string Status = "";

            using (AutomotrizEntities context = new AutomotrizEntities())
            {
                ObjectResult<USP_GET_JOB_STATUS_Result> results =context.USP_GET_JOB_STATUS(nameJob);

                if (results != null)
                {
                    USP_GET_JOB_STATUS_Result result = results.FirstOrDefault();

                    /*
                       current_execution_status
                       ------------------------
                        Value   Description
                        0       Returns only those jobs that are not idle or suspended.
                        1       Executing.
                        2       Waiting for thread.
                        3       Between retries.
                        4       Idle.
                        5       Suspended.
                        7       Performing completion actions.
                    */

                    if (result.current_execution_status == 1)
                        Status = "Ejecutando paquete...";
                    else if (result.current_execution_status == 2)
                        Status = "Esperando hilo...";
                    else if (result.current_execution_status == 3)
                        Status = "Entre reintentos...";
                    else if (result.current_execution_status == 4)
                        Status = "Inactivo...";
                    else if (result.current_execution_status == 5)
                        Status = "Suspendido...";
                    else if (result.current_execution_status == 7)
                        Status = "Realizacion de acciones finalizado...";
                }
            }

            return Status;
        }


    }
}
